package com.sthz.facepay.mapper;

import com.sthz.facepay.model.Category;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

public interface CategoryMapper {
    @Delete({
        "delete from st_category",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into st_category (id, money, ",
        "personnel, datetime, ",
        "remarks, clid)",
        "values (#{id,jdbcType=INTEGER}, #{money,jdbcType=VARCHAR}, ",
        "#{personnel,jdbcType=VARCHAR}, #{datetime,jdbcType=TIMESTAMP}, ",
        "#{remarks,jdbcType=VARCHAR}, #{clid,jdbcType=INTEGER})"
    })
    int insert(Category record);

    @InsertProvider(type=CategorySqlProvider.class, method="insertSelective")
    int insertSelective(Category record);

    @Select({
        "select",
        "id, money, personnel, datetime, remarks, clid",
        "from st_category",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="money", property="money", jdbcType=JdbcType.VARCHAR),
        @Result(column="personnel", property="personnel", jdbcType=JdbcType.VARCHAR),
        @Result(column="datetime", property="datetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
       /* @Result(column="clid", property="clid", jdbcType=JdbcType.INTEGER),*/
        @Result(column="clid", property="classification", one=@One(select="com.sthz.facepay.mapper.ClassificationMapper.getById",fetchType = FetchType.EAGER))

    })
    Category selectByPrimaryKey(Integer id);

    @UpdateProvider(type=CategorySqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Category record);

    @Update({
        "update st_category",
        "set money = #{money,jdbcType=VARCHAR},",
          "personnel = #{personnel,jdbcType=VARCHAR},",
          "datetime = #{datetime,jdbcType=TIMESTAMP},",
          "remarks = #{remarks,jdbcType=VARCHAR},",
          "clid = #{clid,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Category record);
}